﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;//Add Ref
using System.Windows.Media.Imaging;//Add Ref

namespace Day2
{
    public partial class TakePhotoPage : PhoneApplicationPage
    {
        public TakePhotoPage()
        {
            InitializeComponent();
        }

        private void appbarCapture_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
			CameraCaptureTask c = new CameraCaptureTask();
			c.Completed +=new System.EventHandler<Microsoft.Phone.Tasks.PhotoResult>(c_Completed);
			c.Show();
        }

        private void c_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
        {
        	// TODO: Add event handler implementation here.
			if(e.TaskResult == TaskResult.OK){
				Uri u = new Uri(e.OriginalFileName,UriKind.Absolute);
				
				captureImage.Source = new BitmapImage(u);
			}
        }

        private void appbarBrowse_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
			PhotoChooserTask p = new PhotoChooserTask();
			p.Completed +=new System.EventHandler<Microsoft.Phone.Tasks.PhotoResult>(p_Completed);
			p.ShowCamera = true;
			
			p.Show();
        }

        private void p_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
        {
        	// TODO: Add event handler implementation here.
			if(e.TaskResult == TaskResult.OK){
				Uri u = new Uri(e.OriginalFileName,UriKind.Absolute);		
				captureImage.Source = new BitmapImage(u);
			}
        }
    }
}
